package com.example.everying.controller.points;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.everying.annotation.WebLog;
import com.example.everying.context.UserContext;
import com.example.everying.model.entity.user.PointsTransaction;
import com.example.everying.model.vo.content.ActivityArticleVo;
import com.example.everying.model.vo.user.UserInfoVo;
import com.example.everying.service.user.PointsTransactionService;
import com.example.everying.utils.PageParam;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "积分交易")
@RequestMapping("/points/transaction")
public class PointsTransactionController {

    @Autowired
    private PointsTransactionService transactionService;


    //条件查询带分页
    @ApiOperation(value = "分页查询")
    @PostMapping("/page")
    @WebLog(description = "分页查询积分交易")
    public Result<?> list(@RequestBody PageParam<PointsTransaction> query) {
        UserInfoVo userInfoVo = UserContext.getUser();
        if (userInfoVo == null) {
            return Result.fail("用户未登录");
        }
        query.getQuery().setUserId(userInfoVo.getId());
        Page<PointsTransaction> pageParam = new Page<>(query.getPage(), query.getLimit());
        IPage<PointsTransaction> pageModel = transactionService.selectPage(pageParam,query.getQuery());
        return Result.ok(pageModel);
    }



}
